<link rel="stylesheet" href="__PUBLIC__/bootstrap-fileinput/css/fileinput.min.css"/>
<script src="__PUBLIC__/bootstrap-fileinput/js/fileinput.min.js"></script>
<script src="__PUBLIC__/bootstrap-fileinput/js/locales/zh.js"></script>
<div class="modal fade"  id="uploadModal" tabindex="-1" role="dialog">
    <form name="editForm" enctype="multipart/form-data" class="form-horizontal">
        <div class="modal-dialog" role="document" style="width: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">上传图片</h4>
                </div>
                <div class="modal-body" style="width: 800px">
                    <div class="form-group" style="height: 500px">
                        <label for="importUserUrl" class="col-sm-2 control-label">请选择要上传的图片</label>
                        <div class="col-sm-10" style="height: 340px;">
                            <input id="importUserUrl" name="file" class="form-control" type="file">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </form>
    <!-- /.modal-dialog -->
</div>
<input type="hidden" id="inputShow" value="">
<script>
    //初始化fileinput控件（第一次初始化）
    function initFileInput(ctrlName, uploadUrl) {
        var control = $('#importUserUrl');

        var extra = '';
        var key = '';
        var imageUrl = '';
        console.info(ctrlName);
        $('#inputShow').val(ctrlName);
        control.fileinput('refresh',{
            language: 'zh', //设置语言
            uploadUrl: uploadUrl, //上传的地址
            allowedFileExtensions : ["jpg", "png", "gif"],//接收的文件后缀
            showUpload: true, //是否显示上传按钮
            showCaption: false,//是否显示标题
            browseClass: "btn btn-primary", //按钮样式
            initialPreviewConfig:[],
            previewFileIcon: "<i  class='glyphicon glyphicon-king'></i>",
        }).on("fileuploaded", function(event, data) {
            console.info(data);
            console.info(data.response.path);
            console.info(ctrlName);
            if(data.response.success){
                var controlName = $('#inputShow').val();
                $('#'+controlName).val(data.response.path);
            }
        })
    }

</script>